

function ajax(methods: string, url: string) {
  return new Promise((resolve,) => {
    let oajax = new XMLHttpRequest();
    // 创建连接
    oajax.open(methods, url, true);
    // 发送请求
    oajax.send();
    oajax.responseType = 'json'

    // 请求过程
    oajax.onload = function (e: any) {
      console.log('c', e);

      /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/status) */
      if (oajax.status === 200) {
        // console.log('e', e);
        // resolve(e)

      }

    }
    oajax.onreadystatechange = function (e) {
      console.log('2', oajax.responseText);
      /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/readyState) */
      if (oajax.readyState === 4 && (oajax.status === 200 || oajax.status === 304)) {
        resolve(e)
      }


    }
  })

}

export default ajax